package com.balance.anole.client.common.dao.hibernate;

import java.util.List;

import org.hibernate.Query;

import com.balance.anole.client.common.dao.CodeLookDAO;
import com.balance.anole.common.to.CodeLookTO;

public class CodeLookDAOImpl extends BaseDAOImpl implements CodeLookDAO {

	public CodeLookTO getCodeLookTO(Long id) {
		return (CodeLookTO)getHibernateTemplate().get(CodeLookTO.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<CodeLookTO> getCodeLookTOsByCodeType(String CodeType) {
		return getHibernateTemplate().find("from com.balance.anole.common.to.CodeLookTO as cd where cd.codeTypeId = ? order by cd.codeSeq",CodeType);
	}

	@Override
	public void insertOrupdateCodeLookTO(CodeLookTO codeLookTO) {
		getHibernateTemplate().saveOrUpdate(codeLookTO);
	}

	@SuppressWarnings("unchecked")
	@Override
	public CodeLookTO getCodeLookTOByCodeTypeAndCodeId(String codeTypeId,
			String codeId) {
		String hql = "from com.balance.anole.common.to.CodeLookTO as cd where cd.codeTypeId = :codeTypeId and cd.codeId = :codeId";
		Query q = getSession().createQuery(hql);
		q.setParameter("codeTypeId", codeTypeId);
		q.setParameter("codeId", codeId);
		
		List<CodeLookTO> l = q.list();
		
		if(l.size()>0){
			return l.get(0);
		}
		return null;
	}

}